<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/8/27 0027
 * Time: 9:23
 */
namespace app\api\command;
use app\admin\model\Category;
use app\common\model\MoneyLog;
use app\common\model\Packet;
use app\common\model\User;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Db;

class CategoryBuild extends Command {
    protected function configure()
    {
        $this->setName('CategoryBuild')->setDescription('分类创建');
    }

    protected function execute(Input $input, Output $output)
    {
        /* 永不超时 */
        ini_set('max_execution_time', 0);
    }

    protected $category = [63=>['缴费服务','公共服务','办事服务'],118=>['家园服务中心']];

    public function doCron($site_id){
        $categoryModel = new Category();
        $category = $this->category;
        $categoryData = [];

        foreach ($category as $k=>$v){
            foreach ($v as $kk=>$vv){
                $data = [
                    [
                        'site_id'=>$site_id,
                        'pid'=>$k,
                        'type'=>'navigation',
                        'name'=>$vv,
                        'nickname'=>$vv,
                    ]
                ];
                $categoryData[] = $data;
            }
        }
        if(!empty($categoryData)){
            $categoryModel->saveAll($categoryData);
        }
    }
}